package com.ideal.lx_mss.controller;

import com.github.pagehelper.PageInfo;
import com.ideal.lx_mss.common.AjaxResult;
import com.ideal.lx_mss.common.entity.KafkaTableEntity;
import com.ideal.lx_mss.common.entity.KafkaTopicEntity;
import com.ideal.lx_mss.common.entity.MssKafkaEntity;
import com.ideal.lx_mss.mapper.BasicMapper;
import com.ideal.lx_mss.service.KafkaDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutionException;

@RestController
@RequestMapping("/kafka")
public class KafkaTopicController extends BaseController{


    @Autowired
    private KafkaDataService kafkaDataService;
    @Autowired
    private BasicMapper basicMapper;

    /**
     * 获取topic列表
     */

    @GetMapping("/topic/list")
    public AjaxResult list() {
        List<KafkaTopicEntity> list = kafkaDataService.getKafkaTopicList();
        return AjaxResult.success().put("list",list);
    }


    @GetMapping("/topic/pull")
    public AjaxResult pullKafkaDataByTopic(MssKafkaEntity mssKafkaEntity) throws ExecutionException, InterruptedException {

        String ta[] = {"mss_dict","mss_check","mss_logs"};
        for (String s : ta) {
            basicMapper.truncateTables(s);
        }
        HashMap<String, Object> map = kafkaDataService.pullKafkaDataByTopic(mssKafkaEntity);
        return AjaxResult.success().put("ok",map);
    }






}
